﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Automobile.service.Common;
using Automobile.service.Model;
using System.Data;
using System.Data.SqlClient;

namespace Automobile.service.DAL
{
    public class JournalDAL
    {
        SQLHelper helper = new SQLHelper();

        #region 日志操作
        /// <summary>
        /// 日志管理——显示
        /// </summary>
        /// <returns></returns>
        public DataTable ShowJournal(int id)
        {
            SqlParameter[] Empid = { 
                                   new SqlParameter("@empid",id)
                                   };
            return helper.ExecDataTable_Proc("proc_ShowJournal",Empid);
        }
        /// <summary>
        /// 日志管理——根据登录人显示日志条数
        /// </summary>
        /// <returns></returns>
        public string GetJournaCount(int id)
        {
            string sql = "select count(Journa_Id) from journal where Employee_Id="+id;
            return helper.ExecScalar(sql).ToString();
        }
        /// <summary>
        /// 日志管理——清空
        /// </summary>
        /// <returns></returns>
        public int TruncateJournal(int id)
        {
            SqlParameter[] Empid = { 
                                   new SqlParameter("@empid",id)
                                   };
            return helper.ExecNonquery_Proc("proc_truncateJournal",Empid);
        }
        /// <summary>
        /// 日志管理——根据日志内容模糊查询
        /// </summary>
        /// <param name="JournalContent"></param>
        /// <returns></returns>
        public DataTable GetJournalByJournalContent(int id,string JournalContent)
        {
            JournalContent = '%' + JournalContent + '%';
            SqlParameter[] GetContent={
                                          new SqlParameter("@empid",id),
                                              new SqlParameter("@jcontent",JournalContent)
                                          };
            return helper.ExecDataTable_Proc("proc_GetjournaByJourcontent", GetContent);
        }
        #endregion

        #region 仓库信息操作记录
        /// <summary>
        /// 日志管理——添加仓库信息添加的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_AddWareHose(int empid, WareHose w)
        {
            string journacon = "添加仓库名称为" + w.WareHose_Name + "的信息";
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
        /// <summary>
        /// 日志管理——添加仓库信息删除的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_DelWareHose(int empid, string id)
        {
            string journacon = "删除仓库编号为" + id + "的信息";
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
        /// <summary>
        /// 日志管理——添加仓库信息更新的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_UpdWareHose(int empid, WareHose w)
        {
            string journacon = "更新仓库编号为" + w.WareHose_Id + "的信息";
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
        #endregion

        #region 供应商信息操作记录
        /// <summary>
        /// 日志管理——添加供应商信息删除的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_DelSupplier(int empid, string id)
        {
            string journacon = "删除供应商编号为" + id + "的信息";
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
        /// <summary>
        /// 日志管理——添加供应商信息添加的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_AddSupplier(int empid, Supplier s)
        {
            string journacon = "添加供应商" + s.Supplier_Name + "的信息";
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
        /// <summary>
        /// 日志管理——添加供应商信息修改的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_uptSupplier(int empid, Supplier s)
        {
            string journacon = "更新供应商编号为" + s.Supplier_Id + "的信息";
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
        #endregion

        #region 库存信息操作记录
        /// <summary>
        /// 日志管理——添加库存信息添加的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_AddStock(int empid, Stock s)
        {
            string journacon = "添加商品编号为" + s.Product_Id + "的库存信息";
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
        /// <summary>
        /// 日志管理——添加库存信息删除的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_DelStock(int empid, string id)
        {
            string journacon = "删除库存编号为" + id + "的库存信息";
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
        /// <summary>
        /// 日志管理——添加库存信息修改的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_UpdStockById(int empid, Stock s)
        {
            string journacon = "更新库存编号为" + s.Stock_Id + "的库存信息";
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
        #endregion

        #region 会员信息操作记录
        /// <summary>
        /// 日志管理——添加更新会员状态的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public int AddJourna_UptMemberCard_StateByID(int empid, int MemberCard_Id)
        {
            string journacontent = "更新了会员编号为" + MemberCard_Id + "的状态";
            SqlParameter[] journaUpdempstatetrue ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacontent)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaUpdempstatetrue);
        }
        /// <summary>
        /// 日志管理——添加修改会员信息的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public int AddJourna_UptMemberCardByID(int empid, MemberCard m)
        {
            string journacontent = "更新了会员编号为" + m.MemberCard_Id + "的会员信息";
            SqlParameter[] journaUpdempstatetrue ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacontent)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaUpdempstatetrue);
        }
        /// <summary>
        /// 日志管理——添加添加会员信息的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public int AddJourna_AddMemberCard(int empid, MemberCard m)
        {
            string journacontent = "添加了会员:" + m.MemberCard_Name;
            SqlParameter[] journaUpdempstatetrue ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacontent)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaUpdempstatetrue);
        }
        /// <summary>
        /// 日志管理——添加删除会员信息的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public int AddJourna_DelMemberCard(int empid, string id)
        {
            string journacontent = "删除会员编号为" + id + "的信息";
            SqlParameter[] journaUpdempstatetrue ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacontent)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaUpdempstatetrue);
        }
        #endregion

        #region 员工信息操作记录
        /// <summary>
        /// 日志管理——添加登录系统记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public int AddJourna_Landing(int empid)
        {
            string journacontent = "登录系统";
            SqlParameter[] journaUpdempstatetrue ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacontent)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaUpdempstatetrue);
        }
        /// <summary>
        /// 日志管理——添加更新员工信息记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public int AddJourna_UpdEmployeeByempid(int empid, Employee emp)
        {
            string journacontent = "更新员工编号为" + emp.Employee_Id + "的信息";
            SqlParameter[] journaUpdempstatetrue ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacontent)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaUpdempstatetrue);
        }
        /// <summary>
        /// 日志管理——添加员工状态停用记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public int AddJourna_Updempstatefalse(int empid, int id)
        {
            string journacontent = "修改员工编号为" + id + "的状态为停用";
            SqlParameter[] journaUpdempstatetrue ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacontent)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaUpdempstatetrue);
        }
        /// <summary>
        /// 日志管理——添加员工状态启用记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public int AddJourna_Updempstatetrue(int empid, int id)
        {
            string journacontent = "修改员工编号为" + id + "的状态为启用";
            SqlParameter[] journaUpdempstatetrue ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacontent)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaUpdempstatetrue);
        }
        /// <summary>
        /// 日志管理——添加员工信息日志
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_AddEmp(int empid, Employee e)
        {
            string journacon = "添加了一位员工：" + e.Employee_Name;
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
        #endregion

        #region 零售操作记录
        /// <summary>
        /// 日志管理——添加零售订单添加的记录
        /// </summary>
        /// <param name="empid"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public int AddJourna_AddShioments(int empid, Shipments sp)
        {
            string journacon = "添加了单据号为" + sp.Shipments_blitems + "的零售单据";
            SqlParameter[] journaaddemp ={
                                            new SqlParameter("@empid",empid),
                                            new SqlParameter("@journacontent",journacon)
                                        };
            return helper.ExecNonquery_Proc("proc_Addjourna", journaaddemp);
        }
#endregion

    }
}
